<?php

namespace SaaS\Commands;

use Illuminate\Console\Command;

class SaaSInstall extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'saas:install';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '安装SaaS的必要动作';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle(): int
    {
        $this->call('tenancy:install');
        $this->call('migrate');

        // 发布静态资源
        if (app()->runningInConsole()) {
            copy(__DIR__ . '/../../config/tenancy.php', config_path('tenancy.php'));
            copy(app_path('Providers/RouteServiceProvider.php'), app_path('Providers/RouteServiceProvider.php.bak'));
            copy(__DIR__ . '/../Providers/RouteServiceProvider.php', app_path('Providers/RouteServiceProvider.php'));
            copy(__DIR__ . '/../../routes/tenant.php', base_path('routes/tenant.php'));
        }

        return 0;
    }
}
